pclogofandomcom-20200214-history
Memory
As a Windows program Logo uses the memory Windows provides. In enhanced mode, available memory is only limited by the available disk space. Memory Organization When Logo is loaded, it divides the computer's memory into various segments for its own use. These include space for symbols and numbers, and space for lists. The available memory, or workspace, determines the number of procedures and commands you can issue in Logo or the size of files you can load. Workspace Logo workspace is the area of the computer's memory allocated by Logo for the variables, procedures, property lists, and arrays that you create. Access to Logo workspace is attained at toplevel, the command level of Logo where all commands are executed when ENTER is pressed, The question mark (?) Logo prompt displays at toplevel. Commands you type, names you create, and procedures you define are added to workspace as you use Logo. Names, procedures, property lists, and arrays can also be created in a Logo editor. While in a Logo editor, this information is contained in the edit buffer section of memory. When you exit the editor and define the Logo objects you have created, they are copied from the edit buffer to toplevel as if you had typed them in at the Logo command level. They are then installed in the Logo workspace and are available for your use. (Note that a copy remains in the edit buffer.) Garbage Collection Logo adds the information you enter to its workspace until there is no more room. Then, Logo reviews all the information in workspace and discards objects in memory that are no longer being used. This space is reallocated for new storage. This process is known as recycling or in Logo as garbage collection. Logo normally performs a garbage collection when the workspace is full. A garbage collection causes a pause in Logo of as much as one second depending on the speed of the computer. As the workspace begins to fill up, Logo performs more frequent garbage collections which may cause pauses at inconvenient times in a procedure. In this case, the Logo command RECYCLE, which causes Logo to perform a garbage collection, can be used at a point where the pause would not be noticeable. Workspace Contents Logo provides a number of commands that allow you to view what is in your Logo workspace. The PRINTOUT command will display any of the types of Logo objects in workspace or ALL of workspace. You can ERASE any object in workspace if you no longer need it. The contents of the Logo workspace exist in the computer's memory and are available only as long as Logo is loaded and the computer is turned on. The SAVE command will preserve workspace contents in a file on a computer disk. By preserving your workspace on disk, you can exit from Logo and use the LOAD command to restore your Logo workspace to continue your Logo programming at a later time. See the section in this chapter on Files for more information. Workspace Management Logo workspace contains the names, procedures, property lists, and arrays that you create once Logo is loaded. Logo primitives and system names are part of Logo. Although they are available for use in workspace, they are not part of workspace in that they are not saved in workspace files and cannot be erased. Sometimes it canbe convenient to have the Logo objects you create act as primitives or system names in the sense that they are available for use, but are not saved in workspace files and cannot be erased. The BURY primitives provide this capability. These commands include BURY, BURYALL, BURYNAME, BURYPROC, and BURYPROP. When a Logo object, such as a procedure, is buried in Logo workspace it remains available as a command, but does not respond to PRINTOUT commands, cannot be erased, and is not saved in disk files when the SAVE command is used. Buried Logo objects can also be unburied, using commands including UNBURY, UNBURYALL, UNBURYNAME, UNBURYPROC, and UNBURYPROP. Conserving Workspace Memory Like any finite resource, the memory available for Logo workspace is more productive if used efficiently. The following suggestions provide ways for you to achieve more Logo programming power by conserving workspace memory. 1) PRINTOUT workspace contents and ERASE elements you no longer need. 2) Create subprocedures to replace repetitive sections of procedures to reduce text, since workspace must store the complete text of all defined procedures. 3) Use local rather than global variables since global variables always exist in memory and local variable occupy memory space only when their procedure is running. 4) Use tail recursion by putting the recursive procedure call in the last line of the procedure. Recursion requires a copy of the procedure in workspace for each level of recursion except for tail recursion, which only requires one copy, and so uses much less memory. If tail recursion is not possible, sometimes REPEAT, FOR, WHILE or GOTO..LABEL constructions can be substituted which require less workspace memory. Additional Workspace Commands Additional Logo primitives and system names that help you manage your Logo workspace include: Changing Memory Organization When Logo loads, it allocates the computer's available memory in a pattern that is convenient for the majority of Logo users. The Logo command (RECYCLE "TRUE) lists how memory has been divided. For some purposes, it may be useful to allocate memory differently than Logo does automatically. This can be conveniently done via the Environment item on the Option Menu. The dialog box that appears when you choose Option/Environment allows you to change the allocation of memory between nodes, atoms, and playback buffer. The number of nodes determines list space, or general memory storage space, Logo has available. The larger this number, the more variables and procedures that can be kept in Logo workspace. The number of atoms is the total amount of space for numbers and symbols. Each number or symbol is considered an atom. The picture playback buffer determines how many graphics elements can be recalled when the Graphics window is redisplayed.